package cn.cvs.inteceptor;

import cn.cvs.util.Constants;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//登录拦截器
public class LoginInteceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object loginUser = request.getSession().getAttribute(Constants.USER_SESSION);
        if (loginUser!=null){
            return true;
        }
        String contextPath = request.getContextPath();
        response.sendRedirect(contextPath+"/toLogin");
        return false;
    }
}
